/*
 * @Author: 鱿鱼溪学院
 * @Date: 2025-04-26 20:19:37
 * @LastEditTime: 2025-07-28 00:51:02
 * @LastEditors: 鱿鱼溪学院
 * @Description:
 * @FilePath: \yyx-web\src\api\register.ts
 * Copyright 鱿鱼溪学院 by edu v1.0
 * 天道酬勤
 */
import http from '@/utils/http'
import type { AxiosResponse } from 'axios'

//统一接口管理
enum API {
  PHONELOGINWITHOUTCODE_URL = '/aa/user/phoneLoginWithoutVerification',
  REGISTERBYPHONE_URL = '/aa/user/phoneRegister'
}

export interface registerData {
  username: string
  phone: string
  password: string
}

export interface registerPhoneData {
  phone: string
  verificationCode: string
}

export interface registerResponse {
  code: number
  // 可以根据实际接口补充 data 字段
  // data: {
  //   token: string
  // }
}

export function registerByUser(data: registerData): Promise<registerResponse> {
  return http({
    url: 'aa/user/register',
    method: 'post',
    data: data
  }).then((response: AxiosResponse<any>) => {
    // 假设后端返回的 data 中包含 code 字段
    return response.data
  })
}

export function registerByPhone(
  data: registerPhoneData
): Promise<registerResponse> {
  return http({
    url: API.REGISTERBYPHONE_URL,
    method: 'post',
    data: data
  }).then((response: AxiosResponse<any>) => {
    return response.data
  })
}
